#include "widget.h"
#include<QLabel>
#include<QStyle>
#include<QFile>
#include<QPushButton>
#include<QWidget>
#include<QVBoxLayout>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    this->resize(532,500);
    QLabel *label = new QLabel("学习使用QSS",this);
    QPushButton *btn1 = new QPushButton("点我就关窗口",this);
    QPushButton *btn2 = new QPushButton("点我就创建一个新窗口",this);
    label->setAlignment(Qt::AlignCenter);
    btn1->move(150,260);
    btn1->resize(150,50);
    btn2->move(300,260);
    btn2->resize(150,50);
    QVBoxLayout *layout= new QVBoxLayout(this);
    layout->addWidget(label);
    layout->addWidget(btn1);
    layout->addWidget(btn2);
    this->setLayout(layout);

    QFile file(":/test_7_23.qss");
    if(file.open(QFile::ReadOnly | QFile::Text))
    {
        QString style = file.readAll();
        this->setStyleSheet(style);
    }
    connect(btn1,&QPushButton::clicked,[&](){ this ->close();});
    connect(btn2,&QPushButton::clicked,[](){
         QWidget *w = new QWidget(nullptr);
         w->resize(200, 150);
         w->setWindowTitle("我是新窗口");
         w->show();
    });
    btn1->show();
    btn2->show();
    label->show();

}

Widget::~Widget()
{
}

